{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7e790d3c-5f6a-47a5-9ac2-60c027664aa5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "828ab3bd-1a1e-45e6-8640-163dd32a0436",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期Date</th>\n",
       "      <th>指数代码 Index Code</th>\n",
       "      <th>指数名称 Index Name</th>\n",
       "      <th>指数英文名称Index Name(Eng)</th>\n",
       "      <th>成份券代码Constituent Code</th>\n",
       "      <th>成份券名称Constituent Name</th>\n",
       "      <th>成份券英文名称Constituent Name(Eng)</th>\n",
       "      <th>交易所Exchange</th>\n",
       "      <th>交易所英文名称Exchange(Eng)</th>\n",
       "      <th>权重(%)weight</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>600519</td>\n",
       "      <td>贵州茅台</td>\n",
       "      <td>Kweichow Moutai Co Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>4.767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>300750</td>\n",
       "      <td>宁德时代</td>\n",
       "      <td>Contemporary Amperex Technology Co., Limited.</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>Shenzhen Stock Exchange</td>\n",
       "      <td>3.430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>601318</td>\n",
       "      <td>中国平安</td>\n",
       "      <td>Ping An Insurance (Group) Company of China Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>2.851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>600036</td>\n",
       "      <td>招商银行</td>\n",
       "      <td>China Merchants Bank Co Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>2.238</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>300059</td>\n",
       "      <td>东方财富</td>\n",
       "      <td>East Money Information Co Ltd</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>Shenzhen Stock Exchange</td>\n",
       "      <td>1.713</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     日期Date  指数代码 Index Code 指数名称 Index Name 指数英文名称Index Name(Eng)  \\\n",
       "0  20241129              300           沪深300               CSI 300   \n",
       "1  20241129              300           沪深300               CSI 300   \n",
       "2  20241129              300           沪深300               CSI 300   \n",
       "3  20241129              300           沪深300               CSI 300   \n",
       "4  20241129              300           沪深300               CSI 300   \n",
       "\n",
       "   成份券代码Constituent Code 成份券名称Constituent Name  \\\n",
       "0                 600519                  贵州茅台   \n",
       "1                 300750                  宁德时代   \n",
       "2                 601318                  中国平安   \n",
       "3                 600036                  招商银行   \n",
       "4                 300059                  东方财富   \n",
       "\n",
       "                     成份券英文名称Constituent Name(Eng) 交易所Exchange  \\\n",
       "0                          Kweichow Moutai Co Ltd     上海证券交易所   \n",
       "1   Contemporary Amperex Technology Co., Limited.     深圳证券交易所   \n",
       "2  Ping An Insurance (Group) Company of China Ltd     上海证券交易所   \n",
       "3                     China Merchants Bank Co Ltd     上海证券交易所   \n",
       "4                   East Money Information Co Ltd     深圳证券交易所   \n",
       "\n",
       "      交易所英文名称Exchange(Eng)  权重(%)weight  \n",
       "0  Shanghai Stock Exchange        4.767  \n",
       "1  Shenzhen Stock Exchange        3.430  \n",
       "2  Shanghai Stock Exchange        2.851  \n",
       "3  Shanghai Stock Exchange        2.238  \n",
       "4  Shenzhen Stock Exchange        1.713  "
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1=pd.read_excel(\"../000300closeweight.xlsx\")\n",
    "df1=df1.loc[:19,:]\n",
    "df1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "fdcc46c4-8bd8-410d-aa18-6f13a07ffe3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期Date</th>\n",
       "      <th>指数代码 Index Code</th>\n",
       "      <th>指数名称 Index Name</th>\n",
       "      <th>指数英文名称Index Name(Eng)</th>\n",
       "      <th>成份券代码Constituent Code</th>\n",
       "      <th>成份券名称Constituent Name</th>\n",
       "      <th>成份券英文名称Constituent Name(Eng)</th>\n",
       "      <th>交易所Exchange</th>\n",
       "      <th>交易所英文名称Exchange(Eng)</th>\n",
       "      <th>权重(%)weight</th>\n",
       "      <th>地区</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>600519</td>\n",
       "      <td>贵州茅台</td>\n",
       "      <td>Kweichow Moutai Co Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>4.767</td>\n",
       "      <td>SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>300750</td>\n",
       "      <td>宁德时代</td>\n",
       "      <td>Contemporary Amperex Technology Co., Limited.</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>Shenzhen Stock Exchange</td>\n",
       "      <td>3.430</td>\n",
       "      <td>SZ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>601318</td>\n",
       "      <td>中国平安</td>\n",
       "      <td>Ping An Insurance (Group) Company of China Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>2.851</td>\n",
       "      <td>SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>600036</td>\n",
       "      <td>招商银行</td>\n",
       "      <td>China Merchants Bank Co Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>2.238</td>\n",
       "      <td>SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>300059</td>\n",
       "      <td>东方财富</td>\n",
       "      <td>East Money Information Co Ltd</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>Shenzhen Stock Exchange</td>\n",
       "      <td>1.713</td>\n",
       "      <td>SZ</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     日期Date  指数代码 Index Code 指数名称 Index Name 指数英文名称Index Name(Eng)  \\\n",
       "0  20241129              300           沪深300               CSI 300   \n",
       "1  20241129              300           沪深300               CSI 300   \n",
       "2  20241129              300           沪深300               CSI 300   \n",
       "3  20241129              300           沪深300               CSI 300   \n",
       "4  20241129              300           沪深300               CSI 300   \n",
       "\n",
       "   成份券代码Constituent Code 成份券名称Constituent Name  \\\n",
       "0                 600519                  贵州茅台   \n",
       "1                 300750                  宁德时代   \n",
       "2                 601318                  中国平安   \n",
       "3                 600036                  招商银行   \n",
       "4                 300059                  东方财富   \n",
       "\n",
       "                     成份券英文名称Constituent Name(Eng) 交易所Exchange  \\\n",
       "0                          Kweichow Moutai Co Ltd     上海证券交易所   \n",
       "1   Contemporary Amperex Technology Co., Limited.     深圳证券交易所   \n",
       "2  Ping An Insurance (Group) Company of China Ltd     上海证券交易所   \n",
       "3                     China Merchants Bank Co Ltd     上海证券交易所   \n",
       "4                   East Money Information Co Ltd     深圳证券交易所   \n",
       "\n",
       "      交易所英文名称Exchange(Eng)  权重(%)weight  地区  \n",
       "0  Shanghai Stock Exchange        4.767  SH  \n",
       "1  Shenzhen Stock Exchange        3.430  SZ  \n",
       "2  Shanghai Stock Exchange        2.851  SH  \n",
       "3  Shanghai Stock Exchange        2.238  SH  \n",
       "4  Shenzhen Stock Exchange        1.713  SZ  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1[\"地区\"]=df1[\"交易所Exchange\"].map({\n",
    "    \"上海证券交易所\":'SH',\n",
    "    \"深圳证券交易所\":'SZ'\n",
    "})\n",
    "df1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "f76c2b8f-68ef-4f09-a58f-7086cc8f2e55",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1[\"ts_code\"]=df1.apply(lambda x:str(x[\"成份券代码Constituent Code\"])+\".\"+x[\"地区\"],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "dae43c40-0849-44e9-8383-2fbd74affed2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期Date</th>\n",
       "      <th>指数代码 Index Code</th>\n",
       "      <th>指数名称 Index Name</th>\n",
       "      <th>指数英文名称Index Name(Eng)</th>\n",
       "      <th>成份券代码Constituent Code</th>\n",
       "      <th>成份券名称Constituent Name</th>\n",
       "      <th>成份券英文名称Constituent Name(Eng)</th>\n",
       "      <th>交易所Exchange</th>\n",
       "      <th>交易所英文名称Exchange(Eng)</th>\n",
       "      <th>权重(%)weight</th>\n",
       "      <th>地区</th>\n",
       "      <th>ts_code</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>600519</td>\n",
       "      <td>贵州茅台</td>\n",
       "      <td>Kweichow Moutai Co Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>4.767</td>\n",
       "      <td>SH</td>\n",
       "      <td>600519.SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>300750</td>\n",
       "      <td>宁德时代</td>\n",
       "      <td>Contemporary Amperex Technology Co., Limited.</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>Shenzhen Stock Exchange</td>\n",
       "      <td>3.430</td>\n",
       "      <td>SZ</td>\n",
       "      <td>300750.SZ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>601318</td>\n",
       "      <td>中国平安</td>\n",
       "      <td>Ping An Insurance (Group) Company of China Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>2.851</td>\n",
       "      <td>SH</td>\n",
       "      <td>601318.SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>600036</td>\n",
       "      <td>招商银行</td>\n",
       "      <td>China Merchants Bank Co Ltd</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>Shanghai Stock Exchange</td>\n",
       "      <td>2.238</td>\n",
       "      <td>SH</td>\n",
       "      <td>600036.SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20241129</td>\n",
       "      <td>300</td>\n",
       "      <td>沪深300</td>\n",
       "      <td>CSI 300</td>\n",
       "      <td>300059</td>\n",
       "      <td>东方财富</td>\n",
       "      <td>East Money Information Co Ltd</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>Shenzhen Stock Exchange</td>\n",
       "      <td>1.713</td>\n",
       "      <td>SZ</td>\n",
       "      <td>300059.SZ</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     日期Date  指数代码 Index Code 指数名称 Index Name 指数英文名称Index Name(Eng)  \\\n",
       "0  20241129              300           沪深300               CSI 300   \n",
       "1  20241129              300           沪深300               CSI 300   \n",
       "2  20241129              300           沪深300               CSI 300   \n",
       "3  20241129              300           沪深300               CSI 300   \n",
       "4  20241129              300           沪深300               CSI 300   \n",
       "\n",
       "   成份券代码Constituent Code 成份券名称Constituent Name  \\\n",
       "0                 600519                  贵州茅台   \n",
       "1                 300750                  宁德时代   \n",
       "2                 601318                  中国平安   \n",
       "3                 600036                  招商银行   \n",
       "4                 300059                  东方财富   \n",
       "\n",
       "                     成份券英文名称Constituent Name(Eng) 交易所Exchange  \\\n",
       "0                          Kweichow Moutai Co Ltd     上海证券交易所   \n",
       "1   Contemporary Amperex Technology Co., Limited.     深圳证券交易所   \n",
       "2  Ping An Insurance (Group) Company of China Ltd     上海证券交易所   \n",
       "3                     China Merchants Bank Co Ltd     上海证券交易所   \n",
       "4                   East Money Information Co Ltd     深圳证券交易所   \n",
       "\n",
       "      交易所英文名称Exchange(Eng)  权重(%)weight  地区    ts_code  \n",
       "0  Shanghai Stock Exchange        4.767  SH  600519.SH  \n",
       "1  Shenzhen Stock Exchange        3.430  SZ  300750.SZ  \n",
       "2  Shanghai Stock Exchange        2.851  SH  601318.SH  \n",
       "3  Shanghai Stock Exchange        2.238  SH  600036.SH  \n",
       "4  Shenzhen Stock Exchange        1.713  SZ  300059.SZ  "
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "5110af5b-6f72-40bb-aaca-5315a534da24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['600519.SH',\n",
       " '300750.SZ',\n",
       " '601318.SH',\n",
       " '600036.SH',\n",
       " '300059.SZ',\n",
       " '333.SZ',\n",
       " '600900.SH',\n",
       " '600030.SH',\n",
       " '858.SZ',\n",
       " '601166.SH',\n",
       " '601899.SH',\n",
       " '2594.SZ',\n",
       " '600276.SH',\n",
       " '601398.SH',\n",
       " '601328.SH',\n",
       " '2475.SZ',\n",
       " '651.SZ',\n",
       " '600887.SH',\n",
       " '688981.SH',\n",
       " '725.SZ']"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts_code_top_20=df1[\"ts_code\"].tolist()\n",
    "ts_code_top_20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "27d388d8-60d4-4c40-9c67-7d21a44b5fa2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [ts_code, trade_date, open, high, low, close, pre_close, change, pct_chg, vol, amount]\n",
       "Index: []"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts.set_token('35f337e592e9520154d2a0827c491f75ccc87b723d2bec02cea6b78b')\n",
    "pro = ts.pro_api()\n",
    "cols=['ts_code','trade_date','open','high','low','close','pre_close','change','pct_chg','vol','amount']\n",
    "df_all=pd.DataFrame(columns=cols)\n",
    "df_all.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0130afe-3e37-4261-b3fb-9b7f613b7146",
   "metadata": {},
   "outputs": [],
   "source": [
    "for cd in ts_code_top_20:\n",
    "    df_i = pro.daily(ts_code=cd, start_date='20240913', end_date='20241211')\n",
    "    df_all=pd.concat([df_all, df_i])\n",
    "    df_i.to_excel(\"../ts_top_20_20240913_20241211.xlsx\",sheet_name=cd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f57a0209-2e35-4f1c-a4c2-30de3ae4c102",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "554ac3ac-bdfa-4da0-bb38-c653e26e9eac",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pro.daily(ts_code='600519.SH', start_date='20180701', end_date='20180718')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c0d7f706-fb5a-40db-9b4b-f0f6af555c36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20180718</td>\n",
       "      <td>742.43</td>\n",
       "      <td>749.69</td>\n",
       "      <td>735.00</td>\n",
       "      <td>737.44</td>\n",
       "      <td>742.43</td>\n",
       "      <td>-4.99</td>\n",
       "      <td>-0.67</td>\n",
       "      <td>24521.71</td>\n",
       "      <td>1818760.392</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20180717</td>\n",
       "      <td>757.00</td>\n",
       "      <td>757.00</td>\n",
       "      <td>736.02</td>\n",
       "      <td>742.43</td>\n",
       "      <td>754.68</td>\n",
       "      <td>-12.25</td>\n",
       "      <td>-1.62</td>\n",
       "      <td>27806.03</td>\n",
       "      <td>2064190.615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20180716</td>\n",
       "      <td>752.30</td>\n",
       "      <td>764.11</td>\n",
       "      <td>751.03</td>\n",
       "      <td>754.68</td>\n",
       "      <td>746.99</td>\n",
       "      <td>7.69</td>\n",
       "      <td>1.03</td>\n",
       "      <td>32474.87</td>\n",
       "      <td>2454501.604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20180713</td>\n",
       "      <td>742.30</td>\n",
       "      <td>748.10</td>\n",
       "      <td>735.12</td>\n",
       "      <td>746.99</td>\n",
       "      <td>737.54</td>\n",
       "      <td>9.45</td>\n",
       "      <td>1.28</td>\n",
       "      <td>28907.04</td>\n",
       "      <td>2152944.602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>600519.SH</td>\n",
       "      <td>20180712</td>\n",
       "      <td>718.00</td>\n",
       "      <td>741.17</td>\n",
       "      <td>718.00</td>\n",
       "      <td>737.54</td>\n",
       "      <td>719.58</td>\n",
       "      <td>17.96</td>\n",
       "      <td>2.50</td>\n",
       "      <td>40170.04</td>\n",
       "      <td>2947129.140</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code trade_date    open    high     low   close  pre_close  change  \\\n",
       "0  600519.SH   20180718  742.43  749.69  735.00  737.44     742.43   -4.99   \n",
       "1  600519.SH   20180717  757.00  757.00  736.02  742.43     754.68  -12.25   \n",
       "2  600519.SH   20180716  752.30  764.11  751.03  754.68     746.99    7.69   \n",
       "3  600519.SH   20180713  742.30  748.10  735.12  746.99     737.54    9.45   \n",
       "4  600519.SH   20180712  718.00  741.17  718.00  737.54     719.58   17.96   \n",
       "\n",
       "   pct_chg       vol       amount  \n",
       "0    -0.67  24521.71  1818760.392  \n",
       "1    -1.62  27806.03  2064190.615  \n",
       "2     1.03  32474.87  2454501.604  \n",
       "3     1.28  28907.04  2152944.602  \n",
       "4     2.50  40170.04  2947129.140  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f691c475-a364-4d3d-82e9-ec7387166cd4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ced7437a-016b-41fa-9cfa-49df0452a1f8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b158e8a-00ed-424c-8c4a-beb6ec76e081",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
